function search_course() {
	var obj = $("input[type='radio']:checked");
	var textValue = $("#inputValue").val();
	//	alert(textValue);
	if (obj.val() == "0") {
		ajax_courseId(textValue); //调用函数不需要加function
	} else if (obj.val() == "1") {
		ajax_courseName(textValue);
	} else if (obj.val() == "2") {
		ajax_courseTeacher(textValue);
	}
}

function ajax_courseId(courseid) {
	$.ajax({
		url: "/educal-0.0.1-SNAPSHOT/course/"+courseid,
		type: "GET",
		async: true,
		data: {
		},
		dataType: "json",
		success: function(data) {
			if (data.course && data.code == 200) {
				$("#course_table tbody").children().remove();
				var $tab = $('<tr><td>' + data.course.courseid 
						+ '</td><td>' + data.course.coursename 
						+ '</td><td>' + data.course.courseteacher 
						+ '</td><td>' + data.course.startweek + '~' + data.course.endweek 
						+ '</td><td><button onclick="course_delete()">删除</button> <button onclick="course_modify()" id="course_modify">修改</button></td></tr>');
				$("#course_table").append($tab);
			}else{
				$("#course_table tbody").children().remove();
				alert("未找到符合条件的信息，请重新输入查询条件！");
			};
		},
		error: function() {
		},
	});
}

function course_modify(){
	window.open("ad_course_modify.html");
}
function ajax_courseName(coursename) {
	$.ajax({
		url: "/course/name/"+coursename,
		type: "GET",
		async: true,
		data: {
		},
		dataType: "json",
		success: function(data) {
			console.log(coursename);
			if (data.course && data.code == 200) {
				$("#course_table tbody").children().remove();
				for (var i = 0; i < data.course.length; i++) {
					var $tab = $('<tr><td>' + data.course[i].courseid 
						+ '</td><td>' + data.course[i].coursename 
						+ '</td><td>' + data.course[i].courseteacher 
						+ '</td><td>' + data.course[i].startweek + '~' + data.course[i].endweek 
						+ '</td><td><button onclick="course_delete()">删除</button> <button onclick="course_modify()" id="course_modify">修改</button></td></tr>');
					$("#course_table").append($tab);
				}
			}else{
				$("#course_table tbody").children().remove();
				alert("未找到符合条件的信息，请重新输入查询条件！");
			};
		},
		error: function() {
			//alert("no!");
		},
	});
}

function ajax_courseTeacher(courseteacher) {
	$.ajax({
		url: "/course/teacher/"+courseteacher, 
		type: "GET",
		async: true,
		data: {
		},
		dataType: "json",
		success: function(data) {
			if (data.course && data.code == 200) {
				$("#course_table tbody").children().remove();
				for (var i = 0; i < data.course.length; i++) {
					var $tab = $('<tr><td>' + data.course[i].courseid + '</td><td>' + data.course[i].coursename + '</td><td>' + data.course[i].courseteacher + '</td><td>' + data.course[i].startweek + '~' + data.course[i].endweek + '</td><td><button onclick="course_delete()">删除</button> <button onclick="course_modify()" id="course_modify">修改</button></td></tr>');
					$("#course_table").append($tab);
				}
			};
		},
		error: function() {
			//alert("no!");
		},
	});
}

function increase_course() {
	window.open("ad_course_increase.html");
}

function course_delete() {
	var del = confirm("确定删除该课程？");
	if (del == true) {
		alert("已删除该课程！");
	} else {
		alert("已取消");
	}
}
